/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.tthdhm.truyvetduongdi.dao;

import com.tthdhm.truyvetduongdi.pojo.TelephoneInfoPOJO;
import java.sql.PreparedStatement;
import java.util.ArrayList;
import java.util.List;
import com.tthdhm.truyvetduongdi.util.Constants;
import java.sql.Connection;
import java.sql.ResultSet;

/**
 *
 * @author BPT
 */
public class TelephoneInfoDAO {
    private static TelephoneInfoDAO instance;

    private TelephoneInfoDAO() {
    }

    public static TelephoneInfoDAO getInstance() {
        if (instance == null) {
            instance = new TelephoneInfoDAO();
        }
        return instance;
    }
    
    public List<TelephoneInfoPOJO> getTelephoneInfoByCustomerID(String username){
        List<TelephoneInfoPOJO> result = new ArrayList<TelephoneInfoPOJO>();
        Connection conn = null;
        PreparedStatement prepareStatement=null;
        String query = Constants.BLANK_VALUE;
        ResultSet rs = null;
        TelephoneInfoPOJO telephonePOJO;
        try {
            query = "Select * from TelephoneInfo where Username=?";
            conn = com.tthdhm.truyvetduongdi.util.Connection.getConnection();
            if (conn != null) {
                prepareStatement = conn.prepareStatement(query);
                prepareStatement.setString(1, username);
            } else {
                return result;
            }
            prepareStatement.execute();
            rs = prepareStatement.getResultSet();
            while (rs.next()) {
                telephonePOJO = new TelephoneInfoPOJO();
                // Set 
                telephonePOJO.setUsername(username);
                telephonePOJO.setTelephoneID(rs.getString("TelephoneID"));
                telephonePOJO.setVictimID(rs.getInt("VictimID"));

                // Add book on list
                result.add(telephonePOJO);
            }

        } catch (Exception ex) {
//            LogSystem.getInstance().info(
//                    "BookDAO.getAllBook:" + ex);
        } finally {
            try {
                rs.close();
                prepareStatement.close();
                conn.close();
            } catch (Exception ex) {
//                LogSystem.getInstance().info(
//                        "BookDAO.getAllBook: " + sqlEx);
            }
//            LogSystem.getInstance().info(
//                    "BookDAO.getAllBook:End");
        }
        return result;
    }
}
